package zhaoqiang.mediarecoder;

import android.content.Context;
import android.os.Environment;

import java.io.File;

/**
 * Project_name : MediaRecoder
 * Author : zhaoQiang
 * Date : 2015/10/28,14:16
 * Email : zhaoq_hero@163.com
 */
public final class FileUtils {

    private FileUtils(){}

    private static  File targetFile = null;
    public static  File getMediaRecoderFolder(Context context){
        File  ret = null;

        String state= Environment.getExternalStorageState();

        File dir;

        //获取内存卡状态：
        if(state.equals(Environment.MEDIA_MOUNTED)){
            //保存到dcim
            dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

            if(!dir.exists()){
                dir=Environment.getExternalStorageDirectory();
                dir=new File(dir,"MediaRecorder/record");
                if(!dir.exists()){
                    dir.mkdirs();
                }
            }
            targetFile=new File(dir,"Record"+System.currentTimeMillis()+".jpg");
        }else{
            //内部存储区
            dir = context.getFilesDir();
        }

        ret = dir;

        return  ret;
    }

    public static File getImageFile(Context context) {
        //设置 EXTRA_OUTPUT 数值来知道保存文件的位置, fromFile 图片存储的位置
        String state= Environment.getExternalStorageState();

        File dir;

        //获取内存卡状态：
        if(state.equals(Environment.MEDIA_MOUNTED)){
            //保存到dcim
            dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

            if(!dir.exists()){
                dir=Environment.getExternalStorageDirectory();
                dir=new File(dir,"MediaRecorder/Images");
                if(!dir.exists()){
                    dir.mkdirs();
                }
            }
            targetFile=new File(dir,"Image"+System.currentTimeMillis()+".jpg");
        }else{
            //内部存储区
            dir = context.getFilesDir();
        }
        targetFile=new File(dir,"Image"+System.currentTimeMillis()+".jpg");

        return targetFile;
    }
}
